package net.atomtree.corrsepond.execotor;

/**
 * Created by czk on 2016/1/2.
 */

import java.text.MessageFormat;
import java.util.Map;

/**
 * this class include three mode ,every mode express a kind of link url's method
 */
public class StageExecutor {
    /**
     * stagesMode needn't some param
     * such as http://101.204.243.107:4040/api/v1/applications/Spark%20Pi/stages
     * @param URLParam contain required keys
     * @return one url and you can use this to correspond with spark
     */
    public String stagesModeExecutor(Map<String,String> URLParam) throws Exception {
        String applicationURL= ApplicationExecutor.appNameModeExecutor(URLParam);
        String stageURL=applicationURL+"stages/";
        return stageURL;
    }
    /**
     *  this executor need you provide a param map,must contain 'host','port','stageId' keys
     *  such as http://101.204.243.107:4040/api/v1/applications/Spark%20Pi/stages/[stage-id]
     * @param URLParam contain required keys
     * @return one url and you can use this to correspond with spark
     */
    public String linkByIdModeExecutor(Map<String,String> URLParam) throws Exception {
        String stageURL=stagesModeExecutor(URLParam);
        String stageURLById=MessageFormat.format(stageURL+"{0}/",URLParam.get("stageId"));
        return stageURLById;
    }

    /**
     *  this executor need you provide a param map,must contain 'host','port','stageId' 'attemptId' keys
     *  such as http://101.204.243.107:4040/api/v1/applications/Spark%20Pi/stages/[stage-id]/[stage-attempt-id]
     * @param URLParam contain required keys
     * @return one url and you can use this to correspond with spark
     */
    public String linkByAttemptIdModeExecutor(Map<String,String> URLParam) throws Exception {
        String stageURL=stagesModeExecutor(URLParam);
        String stageURLByAttemptId=MessageFormat.format(stageURL+"{0}/{1}/",URLParam.get("stageId"),URLParam.get("attemptId"));
        return stageURLByAttemptId;
    }
}
